<template>
  <div
    class="home-container mt-[30px] flex flex-col justify-center items-center"
  >
    <h1 class="text-[36px]">个人简历</h1>
    <div class="w-[100%] flex justify-center">
      <embed
        v-if="resumeInfo"
        :src="`http://localhost:8081/${resumeInfo.filePath}`"
        type="application/pdf"
        width="100%"
        height="800px"
      />
    </div>
  </div>
</template>

<script>
import { ref, onMounted, inject, computed } from "vue";
import Api from "@/api";
import { useRouter } from "vue-router";

export default {
  setup() {
    const router = useRouter();
    const globalState = inject("globalState");
    const username = computed(() => globalState.username);
    const resumeInfo = ref(null);
    const getSelfResume = () => {
      Api.getUserResume(username.value).then((res) => {
        if (res.code !== 0) {
          return ElMessage.error(res.message);
        }
        const result = res.data;
        if (!result) {
          setTimeout(() => {
            router.push("/");
          }, 2000)
          return ElMessage.error("你还没有上传简历哦");
        }
        resumeInfo.value = result;
      });
    };
    onMounted(() => {
      getSelfResume();
    });

    return {
      resumeInfo,
    };
  },
};
</script>

<style lang="scss">
.el-tabs__content {
  width: 100%;
}
</style>
